#!/usr/bin/env bash
# An utility script to provide GUI available source optical disk drives
# FIXME: Should be named listOpticalDiskdrive instead of listDvdDrive
# Copyright © 2013 Colin GILLE / congelli501
# Copyright © 2017 slacka et. al.

# This file is part of WoeUSB.
#
# WoeUSB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# WoeUSB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WoeUSB  If not, see <http://www.gnu.org/licenses/>.

## Makes debuggers' life easier - Unofficial Bash Strict Mode
## BASHDOC: Shell Builtin Commands - Modifying Shell Behavior - The Set Builtin
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail

declare optical_disk_drive_devfs_path

while read sysfs_block_device_path; do
	if echo "${sysfs_block_device_path}"\
		| grep '/block/sr' > /dev/null; then
		optical_disk_drive_devfs_path="/dev/$(basename "${sysfs_block_device_path}")"
		echo "${optical_disk_drive_devfs_path}"
		echo "${optical_disk_drive_devfs_path} - $(cat "${sysfs_block_device_path}/device/model")"
	fi
done < <(\
	find\
		/sys/block\
		-maxdepth 1\
		-mindepth 1\
	)

exit 0
